Skip to content

Move natvis files from src/etc/natvis to debugger_visualizer attributes#154027

Open
clarfonthey wants to merge 3 commits into
rust-lang:mainfrom
clarfonthey:natvis
Open

Move natvis files from src/etc/natvis to debugger_visualizer attributes#154027
clarfonthey wants to merge 3 commits into
rust-lang:mainfrom
clarfonthey:natvis

Conversation

@clarfonthey
Copy link
Copy Markdown
Contributor

@clarfonthey clarfonthey commented Mar 18, 2026

View all comments

This is the "easy part" of a massive rabbit hole that I fell into trying to figure out how the current debug visualizers for hashmaps could potentially be moved into the hashbrown crate, while still being able to leverage them for libstd.

For natvis, it's pretty easy to separate out what belongs where, and we basically already do this. This just takes it a slight step further and attempts to move them into their relevant crates, and we'll see if it breaks everything in CI. For lack of a better place, this moves the "intrinsic" (should probably be renamed to "primitive") natvis file into the libcore crate, since no_core is unstable anyway.

The Python scripts are an absolute mess, and that's going to take some asking around. So, instead of stalling this part on that being done, I decided to just offer this PR and we'll see if it can work and hopefully make it easier for people to modify the debug visualizers in the standard library, at least for Windows.


Worth also mentioning right now that I don't have a copy of Windows proper to test this on, so, I'm mostly relying on CI/others to verify that this actually doesn't break anything.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 18, 2026

r? @clubby789

rustbot has assigned @clubby789.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 18, 2026

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc labels Mar 18, 2026
Comment thread src/tools/compiletest/src/lib.rs Outdated
@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented Mar 18, 2026

// This will cause the Microsoft linker to embed .natvis info into the PDB file
let natvis_dir_path = self.sess.opts.sysroot.path().join("lib\\rustlib\\etc");
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
for entry in natvis_dir {
match entry {
Ok(entry) => {
let path = entry.path();
if path.extension() == Some("natvis".as_ref()) {
let mut arg = OsString::from("/NATVIS:");
arg.push(path);
self.link_arg(arg);
}
}
Err(error) => {
self.sess.dcx().emit_warn(errors::NoNatvisDirectory { error });
}
}
}
}
can be removed after these changes, right?

@clubby789
Copy link
Copy Markdown
Contributor

clubby789 commented Apr 13, 2026

LGTM from the compiletest side once the pretty printer files changes are removed, but I don't have a Windows system to check if the above comment about the linker is true
r? compiler

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 13, 2026
@rustbot rustbot assigned JonathanBrouwer and unassigned clubby789 Apr 13, 2026
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

I also don't have windows
r? bjorn3
I think I remember you knowing things about windows?

@rustbot rustbot assigned bjorn3 and unassigned JonathanBrouwer Apr 13, 2026
@bjorn3
Copy link
Copy Markdown
Member

bjorn3 commented Apr 13, 2026

I haven't really touched Windows in years and never did any native development on it. I know some linkage related things because I was trying to get weak linkage working on Windows for EII. As such I don't think I'm a suitable reviewer.

@clubby789
Copy link
Copy Markdown
Contributor

Hmm... @michaelwoerister reviewed this code originally. Any thoughts?

@rustbot

This comment has been minimized.

@clarfonthey
Copy link
Copy Markdown
Contributor Author

// This will cause the Microsoft linker to embed .natvis info into the PDB file
let natvis_dir_path = self.sess.opts.sysroot.path().join("lib\\rustlib\\etc");
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
for entry in natvis_dir {
match entry {
Ok(entry) => {
let path = entry.path();
if path.extension() == Some("natvis".as_ref()) {
let mut arg = OsString::from("/NATVIS:");
arg.push(path);
self.link_arg(arg);
}
}
Err(error) => {
self.sess.dcx().emit_warn(errors::NoNatvisDirectory { error });
}
}
}
}

can be removed after these changes, right?

Looking into it, this appears to be the case; the loop below this section that collects the natvis files from all compiled crates should be sufficient. Removed it.

@clarfonthey clarfonthey force-pushed the natvis branch 2 times, most recently from b14e911 to 40db624 Compare April 13, 2026 17:18
@rust-log-analyzer

This comment has been minimized.

@ChrisDenton
Copy link
Copy Markdown
Member

This looks right to me. The only possible downside I can think of is that this now loads all the natvis files into memory and then writes them out to temporary files (with more obscure file names). But a) the size is not large and b) that's just like how user natvis files are treated anyway. So I don't think it's much of a downside. If it is advantageous to optimise this then such an optimisation should be applied outside of the standard library too.

@clarfonthey
Copy link
Copy Markdown
Contributor Author

I would be truly shocked if 14KiB of XML was what broke the bank for compiling on Windows.

@rust-bors

This comment has been minimized.

Copy link
Copy Markdown
Member

@bjorn3 bjorn3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=bjorn3,ChrisDenton after fixing the conflicts

View changes since this review

@bjorn3 bjorn3 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 5, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ollie27
Copy link
Copy Markdown
Contributor

ollie27 commented Jun 5, 2026

I guess this will need updating:

windbg -c ".nvload %rust_etc%\intrinsic.natvis; .nvload %rust_etc%\liballoc.natvis; .nvload %rust_etc%\libcore.natvis;" %*

Or rust-windbg.cmd could be removed completely given that it's presumably not useful anymore and rustup doesn't even install a forwarder for it.

@clarfonthey
Copy link
Copy Markdown
Contributor Author

clarfonthey commented Jun 6, 2026

Wow, that script hasn't been touched in 8 years. I'm going to leave it in this PR but would say it's fair to remove if you want to try submitting a PR that removes it and seeing who objects.

@clarfonthey
Copy link
Copy Markdown
Contributor Author

@bors r=bjorn3,ChrisDenton rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 6, 2026

📌 Commit d6bf47d has been approved by bjorn3,ChrisDenton

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 6, 2026
@clarfonthey
Copy link
Copy Markdown
Contributor Author

@bors r-

Right, brain fart. That script should be modified too.

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 6, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 6, 2026

This pull request was unapproved.

View changes since this unapproval

@clarfonthey clarfonthey changed the title Experiment: Move natvis files from src/etc/natvis to debugger_visualizer attributes Move natvis files from src/etc/natvis to debugger_visualizer attributes Jun 6, 2026
@clarfonthey
Copy link
Copy Markdown
Contributor Author

clarfonthey commented Jun 6, 2026

Gonna defer to the incredibly democratic and sound process of asking Windows users on Zulip if they care: #general > rust-windbg script?

Kind of agree that the best course of action would be to just remove the script and update the dev guide, which appear to be the only relevant places rust-windbg is even mentioned. Dev guide PR is rust-lang/rustc-dev-guide#2894

@ChrisDenton
Copy link
Copy Markdown
Member

I admit I forgot rust-windbg.cmd exists but I'd be surprised if nobody was using it, even if it's a pain to find.

@clarfonthey
Copy link
Copy Markdown
Contributor Author

Since this was suggested:

@rustbot ping windows

But personally, I think to get this out of the door for now, I like the idea of just leaving a message in the script and waiting for some predetermined amount of time to see if anyone notices. I assume that the answer will just be to delete the script, but figure people are still using it.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 6, 2026

Hey Windows Group! This issue has been identified as a good "Windows candidate".
In case it's useful, here are some instructions for tackling these sorts of
issues. Maybe take a look?
Thanks! <3

cc @albertlarsan68 @arlosi @ChrisDenton @danielframpton @dpaoliello @gdr-at-ms @kennykerr @luqmana @nico-abram @retep998 @sivadeilra @wesleywiser

@rustbot rustbot added the O-windows Operating system: Windows label Jun 6, 2026
@Walnut356
Copy link
Copy Markdown
Contributor

Walnut356 commented Jun 7, 2026

Just a heads up, CI probably won't catch any issues with this. AFAIK, the only semi-reliable test runner for debug info is aarch64-apple. As of a day or 2 ago, running tests/debuginfo on windows MSVC results in 56 failed tests on my computer. Tbh, I don't really trust the tests that do pass either. Many have been disabled for not working rather than being properly fixed. The tests that are left don't exercise everything the visualizers output, nor do they test the inputs very well. I'm working on fixing that as part of GSoC, but microsoft's debugger is lowest on the priority list unfortunately.

All that said, imo this 100% needs to be tested by hand by somebody before it gets merged.

I've given my general sentiment on this change on zulip (tl;dr, i would prefer almost any alternative that doesn't use #![debugger_visualizer] within Rust itself). If the consensus is that this is the best solution though, I have a windows machine I can test this on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants